* try to predict mass shootings

set more off
set scheme lean2

include "bill-analysis/bill_setup.do"

loc out "`out'/predict-shoot"   // path for regression output
cap mkdir `out'

// specify additional variables
// ----------------------------------------------------------------------------
capture drop logpop
gen double logpop = log(pop_all)
la var logpop "Log Population"
loc demo "logpop `demo'"
loc controls = "`politics' `demo' `yfe'"


// use the main control variables to predict mass shootings {{{
// ----------------------------------------------------------------------------
eststo clear
loc m = 1
loc dv "shoot"

areg `dv' `demo' i.year `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' `politics' `demo' i.year `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' `controls' `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' L.`billdv' `controls' `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' L.`billdv' `controls' `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' L.laws_tighten `controls' `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' L.laws_loosen `controls' `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

writemodel using "`out'/predict_shoot_basic", ext(csv) /*
    */ drop(*.year) order(L.`billdv' L.`lawdv' /*
    */      L.laws_tighten L.laws_loosen `politics')
// }}}


// drop one state {{{
// ----------------------------------------------------------------------------
eststo clear
qui levelsof fips, loc(states)
foreach s of local states {
    preserve
        drop if fips == `s'
        areg shoot `controls' `rng', `linopt'
        qui estadd local sfix = "Yes"
        if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
        eststo m`m', title("`s'")
        loc m = `m' + 1
    restore
}
writemodel using "`out'/predict_shoot_dropstate", ext(csv) /*
    */ drop(*.year) order(`politics')
// }}}


// can gun policy predict mass shootings? {{{
// ---------------------------------------------------------------------------
eststo clear

areg `dv' handgun_wait longgun_wait buysell_atleast* handgun_permit  /*
    */ bgcheck_handgun bgcheck_all assault_ban_any ccw_shall  /*
    */ ccw_none `demo' i.year `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

areg `dv' handgun_wait longgun_wait buysell_atleast* handgun_permit  /*
    */ bgcheck_handgun bgcheck_all assault_ban_any ccw_shall  /*
    */ ccw_none `politics' `demo' i.year `rng', `linopt'
qui estadd local sfix = "Yes"
if regexm("`controls'", "i\.year") qui estadd local yfix "Yes"
eststo m`m', title("`dv'")
loc m = `m' + 1

writemodel using "`out'/predict_shoot_policies", ext(csv) /*
    */ drop(*.year) order(handgun_wait longgun_wait buysell_atleast18   /*
    */      buysell_atleast21 handgun_permit bgcheck_handgun bgcheck_all /*
    */      assault_ban_any ccw_shall ccw_none `politics')
// }}}
// vim: foldmethod=marker
